<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">



  <meta name="description" content="一个简单的小demo"/>




  <meta name="keywords" content="python, 八一" />



  <meta name="baidu-site-verification" content="HhUstaSjr0" />



  <meta name="google-site-verification" content="UA-102975942-1" />






  <link rel="alternate" href="/atom.xml" title="八一">




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=2.6.0" />



<link rel="canonical" href="https://bay1.top/2017/03/18/一个简单的小demo/"/>


<link rel="stylesheet" type="text/css" href="/css/style.css?v=2.6.0" />
<link rel="stylesheet" type="text/css" href="/css/prettify.css" media="screen" />
<link rel="stylesheet" type="text/css" href="/css/sons-of-obsidian.css" media="screen" />



  <link rel="stylesheet" type="text/css" href="/lib/fancybox/jquery.fancybox.css" />




  
  <script id="baidu_analytics">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?9a885cc9fb6cd7bcef579deb8efe8a70";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>



  <script id="google_analytics">
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

        ga('create', 'UA-102975942-1', 'auto');
        ga('send', 'pageview');
  </script>










    <title> 一个简单的小demo - 八一 </title>
  </head>

  <body><div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/." class="logo">八一</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>

<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    
      <a href="/archives">
        <li class="mobile-menu-item">
          
          
            文章
          
        </li>
      </a>
    
      <a href="/tags">
        <li class="mobile-menu-item">
          
          
            标签
          
        </li>
      </a>
    
      <a href="/about">
        <li class="mobile-menu-item">
          
          
            关于/友链
          
        </li>
      </a>
    
      <a href="/search">
        <li class="mobile-menu-item">
          
          
            站内搜索
          
        </li>
      </a>
    
  </ul>
</nav>

    <div class="container" id="mobile-panel">
      <header id="header" class="header"><div class="logo-wrapper">
  <a href="/." class="logo">八一</a>
</div>

<nav class="site-navbar">
  
    <ul id="menu" class="menu">
      
        <li class="menu-item">
          <a class="menu-item-link" href="/archives">
            
            
              文章
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/tags">
            
            
              标签
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/about">
            
            
              关于/友链
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/search">
            
            
              站内搜索
            
          </a>
        </li>
      
    </ul>
  
</nav>

      </header>

      <main id="main" class="main">
        <div class="content-wrapper">
          <div id="content" class="content">
            
  
  <article class="post">
    <header class="post-header">
      <h1 class="post-title">
        
          一个简单的小demo
        
      </h1>

      <div class="post-meta">
        <span class="post-time">
          2017-03-18
        </span>
        
        
        
      </div>
    </header>

    
    

    <div class="post-content">
      
        <p>最近一直在学习python，但是课程也比较紧张，进度一直很慢 <a id="more"></a><br>不过也学得差不多了，毕竟上学期学了c++</p>
<blockquote>
<p>语言都是差不多的，为了复习一下简单的函数和列表，字典，的用法,也是写着玩吧。<br>这里写了上学期用c++写过的一个简单的学生信息管理系统<br>下面的代码没有读取文本或者数据库的功能，只是很简单的输入输出，也没有涉及类<br>满眼while,就当练习打字了吧。。。。。。</p>
</blockquote>
<figure class="highlight py"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/env python</span></span><br><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment">#各部分功能的实现</span></span><br><span class="line"><span class="comment">#1.添加功能</span></span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line">student = []</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">AddStudents</span><span class="params">()</span>:</span></span><br><span class="line">    print(<span class="string">"请依次填入下列信息："</span>)</span><br><span class="line">    senub=input(<span class="string">"序号："</span>)</span><br><span class="line">    name=input(<span class="string">"姓名:"</span>)</span><br><span class="line">    age=input(<span class="string">"年龄:"</span>)</span><br><span class="line">    StudentNumber=input(<span class="string">"学号："</span>)</span><br><span class="line">    Newstudent=&#123;<span class="string">"senub"</span>:senub,<span class="string">"name"</span>:name,<span class="string">"age"</span>:age,<span class="string">"StudentNumber"</span>:StudentNumber&#125;</span><br><span class="line">    student.append(Newstudent)</span><br><span class="line">    trastudents()</span><br><span class="line">    print(<span class="string">"添加成功！"</span>)</span><br><span class="line">    print(<span class="string">"三秒后返回"</span>)</span><br><span class="line">    time.sleep(<span class="number">3</span>)</span><br><span class="line"><span class="comment">#2.删除功能</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">DelStudents</span><span class="params">()</span>:</span></span><br><span class="line">    trastudents()</span><br><span class="line">    Delnum=int(input(<span class="string">"请输入你要删除的学生序号："</span>))</span><br><span class="line">    <span class="keyword">del</span> student[Delnum<span class="number">-1</span>]</span><br><span class="line">    trastudents()</span><br><span class="line">    print(<span class="string">"删除成功！"</span>)</span><br><span class="line">    print(<span class="string">"亲，删除之后学生序号会变哦！"</span>)</span><br><span class="line">    print(<span class="string">"三秒后返回"</span>)</span><br><span class="line">    time.sleep(<span class="number">3</span>)</span><br><span class="line"><span class="comment">#3.修改功能</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">ModStudents</span><span class="params">()</span>:</span></span><br><span class="line">    Modnum=int(input(<span class="string">"请输入你要修改的学生序号："</span>))</span><br><span class="line">    <span class="keyword">try</span>:</span><br><span class="line">        print(<span class="string">"序号     姓名     年龄     学号"</span>)</span><br><span class="line">        print(student[Modnum - <span class="number">1</span>][<span class="string">'senub'</span>],student[Modnum - <span class="number">1</span>][<span class="string">'name'</span>],student[Modnum - <span class="number">1</span>][<span class="string">'age'</span>],student[Modnum - <span class="number">1</span>][<span class="string">'StudentNumber'</span>])</span><br><span class="line">    <span class="keyword">except</span>(IndexError):</span><br><span class="line">        print(<span class="string">"序号填写错误，请检查输入！"</span>)</span><br><span class="line">        ModStudents()</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        print(<span class="string">"请依次填入下列信息："</span>)</span><br><span class="line">        senub = input(<span class="string">"序号："</span>)</span><br><span class="line">        name = input(<span class="string">"姓名:"</span>)</span><br><span class="line">        age = input(<span class="string">"年龄:"</span>)</span><br><span class="line">        StudentNumber = input(<span class="string">"学号："</span>)</span><br><span class="line">        student[Modnum - <span class="number">1</span>][<span class="string">'senub'</span>]=senub</span><br><span class="line">        student[Modnum - <span class="number">1</span>][<span class="string">'name'</span>]=name</span><br><span class="line">        student[Modnum - <span class="number">1</span>][<span class="string">'age'</span>]=age</span><br><span class="line">        student[Modnum - <span class="number">1</span>][<span class="string">'StudentNumber'</span>]=StudentNumber</span><br><span class="line">        trastudents()</span><br><span class="line">        print(<span class="string">"修改成功！"</span>)</span><br><span class="line">        print(<span class="string">"三秒后返回"</span>)</span><br><span class="line">        time.sleep(<span class="number">3</span>)</span><br><span class="line"><span class="comment">#4.查询功能</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">QueStudents</span><span class="params">()</span>:</span></span><br><span class="line">    Quenum=int(input(<span class="string">"请输入你要查询的学生序号："</span>))</span><br><span class="line">    <span class="keyword">try</span>:</span><br><span class="line">        print(<span class="string">"序号     姓名     年龄     学号"</span>)</span><br><span class="line">        print(<span class="string">"%s     %s      %s     %s"</span> % (student[Quenum<span class="number">-1</span>][<span class="string">'senub'</span>],student[Quenum<span class="number">-1</span>][<span class="string">'name'</span>], student[Quenum<span class="number">-1</span>][<span class="string">'age'</span>], student[Quenum<span class="number">-1</span>][<span class="string">'StudentNumber'</span>]))</span><br><span class="line">        Return= input(<span class="string">"输入Y返回:"</span>)</span><br><span class="line">        <span class="keyword">if</span> Return <span class="keyword">in</span> (<span class="string">'Y'</span>, <span class="string">'y'</span>):</span><br><span class="line">            main()</span><br><span class="line">        <span class="keyword">else</span> :</span><br><span class="line">            print(<span class="string">"输入有误，强制退出！"</span>)</span><br><span class="line">            Out()</span><br><span class="line">    <span class="keyword">except</span>(IndexError):</span><br><span class="line">        print(<span class="string">"序号填写错误，请检查输入！"</span>)</span><br><span class="line">        QueStudents()</span><br><span class="line"><span class="comment">#5.遍历所有学生信息</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">trastudents</span><span class="params">()</span>:</span></span><br><span class="line">    print(<span class="string">"*"</span>*<span class="number">30</span>)</span><br><span class="line">    print(<span class="string">"序号     姓名     年龄     学号"</span>)</span><br><span class="line">    <span class="keyword">for</span> temp <span class="keyword">in</span> student:</span><br><span class="line">        print(<span class="string">"%s     %s      %s     %s"</span>%(temp[<span class="string">'senub'</span>],temp[<span class="string">'name'</span>],temp[<span class="string">'age'</span>],temp[<span class="string">'StudentNumber'</span>]))</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Out</span><span class="params">()</span>:</span></span><br><span class="line">    exit()</span><br><span class="line">    print(<span class="string">"退出成功，欢迎下次使用！"</span>)</span><br><span class="line"><span class="comment">#学生管理系统登录页面</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">while</span> <span class="keyword">True</span>:</span><br><span class="line">        <span class="keyword">print</span> (<span class="string">"*"</span>*<span class="number">30</span>)</span><br><span class="line">        print(<span class="string">"     欢迎登录学生管理系统"</span>)</span><br><span class="line">        print(<span class="string">"--1.添加学生信息"</span>)</span><br><span class="line">        print(<span class="string">"--2.删除学生信息"</span>)</span><br><span class="line">        print(<span class="string">"--3.修改学生信息"</span>)</span><br><span class="line">        print(<span class="string">"--4.查询学生信息"</span>)</span><br><span class="line">        print(<span class="string">"--5.遍历学生信息"</span>)</span><br><span class="line">        print(<span class="string">"--6.退出"</span>)</span><br><span class="line">        <span class="keyword">print</span> (<span class="string">"*"</span>*<span class="number">30</span>)<span class="comment">#打印功能引导模块</span></span><br><span class="line">        inPut=int(input(<span class="string">"请输入你的选择："</span>))</span><br><span class="line">        <span class="keyword">if</span> inPut==<span class="number">1</span>:</span><br><span class="line">            AddStudents()</span><br><span class="line">        <span class="keyword">elif</span> inPut==<span class="number">2</span>:</span><br><span class="line">            DelStudents()</span><br><span class="line">        <span class="keyword">elif</span> inPut==<span class="number">3</span>:</span><br><span class="line">            ModStudents()</span><br><span class="line">        <span class="keyword">elif</span> inPut==<span class="number">4</span>:</span><br><span class="line">            QueStudents()</span><br><span class="line">        <span class="keyword">elif</span> inPut==<span class="number">5</span>:</span><br><span class="line">            trastudents()</span><br><span class="line">        <span class="keyword">elif</span> inPut==<span class="number">6</span>:</span><br><span class="line">            Out()</span><br><span class="line">        <span class="keyword">else</span> :</span><br><span class="line">            print(<span class="string">"亲，请仔细检查你的输入！"</span>)</span><br><span class="line">            Check = input(<span class="string">"是否要重新输入？（Y/N）"</span>)</span><br><span class="line">            <span class="keyword">if</span> Check <span class="keyword">in</span> (<span class="string">'Y'</span>,<span class="string">'y'</span>):</span><br><span class="line">                main()</span><br><span class="line">            <span class="keyword">else</span> :</span><br><span class="line">                Out()<span class="comment">#对各个选项进行具体的操作</span></span><br><span class="line"><span class="comment">#主体</span></span><br><span class="line">main()</span><br></pre></td></tr></table></figure>
      
    </div>

    
      
      



      
      
    

    
      <footer class="post-footer">
        
          <div class="post-tags">
            
              <a href="/tags/python/">python</a>
            
          </div>
        
        
        
  <nav class="post-nav">
    
      <a class="prev" href="/2017/03/28/python虚拟环境的搭建/">
        <i class="iconfont icon-left"></i>
        <span class="prev-text nav-default">python虚拟环境的搭建</span>
        <span class="prev-text nav-mobile">上一篇</span>
      </a>
    
    
      <a class="next" href="/2017/03/09/关于html登录界面/">
        <span class="next-text nav-default">关于html登录界面的简单学习</span>
        <span class="prev-text nav-mobile">下一篇</span>
        <i class="iconfont icon-right"></i>
      </a>
    
  </nav>

      </footer>
    

  </article>


          </div>
          
  <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div> 
    </div>
  </div>


        </div>
      </main>

      <footer id="footer" class="footer">

  <div class="social-links">
    
      
        
          <a href="https://github.com/bay1" class="iconfont icon-github" title="github"></a>
        
      
    
      
        
          <a href="http://weibo.com/3190704711/profile?topnav=1&wvr=6&is_all=1" class="iconfont icon-weibo" title="weibo"></a>
        
      
    
      
    
      
    
      
    
    
    
  </div>


<div class="copyright">
  <span class="copyright-year">
    
    &copy; 
     
      2016 - 
    
    2018
    <span class="author">bay1</span>
  </span>
</div>
      </footer>

      <div class="back-to-top" id="back-to-top">
        <i class="iconfont icon-up"></i>
      </div>
    </div>

    
  
  <script type="text/javascript">
    var disqus_config = function () {
        this.page.url = 'https://bay1.top/2017/03/18/一个简单的小demo/';
        this.page.identifier = '2017/03/18/一个简单的小demo/';
        this.page.title = '一个简单的小demo';
    };
    (function() {
    var d = document, s = d.createElement('script');

    s.src = '//https-blog-flywinky-top-1.disqus.com/embed.js';

    s.setAttribute('data-timestamp', +new Date());
    (d.head || d.body).appendChild(s);
    })();  
  </script>



    
  





  
    <script type="text/javascript" src="/lib/jquery/jquery-3.1.1.min.js"></script>
  

  
    <script type="text/javascript" src="/lib/slideout/slideout.js"></script>
  

  
    <script type="text/javascript" src="/lib/fancybox/jquery.fancybox.pack.js"></script>
  


    <script type="text/javascript" src="/js/src/even.js?v=2.6.0"></script>
<script type="text/javascript" src="/js/src/bootstrap.js?v=2.6.0"></script>
<script src="/js/prettify.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $('pre').addClass('prettyprint');
   prettyPrint();
 })
</script>
  </body>
</html>
